# -*- coding: utf-8 -*-
from odoo import models, fields, api, tools, _
from odoo.exceptions import ValidationError, Warning


SAVE_UNIT_TYPE = [
    ('use','使用单位'),
    ('maintenance','维保单位'),
    ('salver','救援人员'),
    ('salver_company','网格救援单位'),
    ('110','公安'),
    ('119','消防'),
    ('120','急救'),
]

SALVAGER_ROLES = [
    ('head_of_unit', '公司负责人'),
    ('first_salvager', '第一救援负责人'),
    ('second_salvager', '第二救援负责人'),
    ('third_salvager', '第三救援负责人'),
    # ('propertity_manager', '物业负责人'),
    # ('community_manager','小区负责人'),
    # ('lift_manager', '电梯负责人'),
    # ('lift_salvager_manager', '电梯负责人'),
    ('use_company_manager', '电梯安全管理员'),
    ('lift_manager', '电梯作业人员'),
    ('qs_manager','监察单位负责人'),
    ('check_manager','检验单位负责人'),
]

RESPONSE_LEVELS = [
    ('1', '一级响应'),
    ('2', '二级响应'),
    ('3', '三级响应'),
]

CONFIG_TYPE = [
    ('save', '救援配置'),
    ('repair', '报修配置'),
    ('compliant', '投诉配置'),
]


class ErPublic(models.Model):
    """
    公共救援详细信息
    """
    _name = "tyibs.er.public"

    name = fields.Char(string=u"名称", size=100, required=True)
    phone = fields.Char(string=u"电话", size=100, required=True)
    remark = fields.Text(string=u"备注")

    _sql_constraints = [
        ("unique_name", "unique(name)", "单位名称已经存在"),
        ("unique_phone", "unique(phone)", "电话号码已经存在"),
    ]


class ErConfig(models.Model):
    """
    调度配置
    """
    _name = "tyibs.er.call.config"
    _rec_name = "role"
    _order = "order_number"

    config_type = fields.Selection(CONFIG_TYPE, string=u"配置类型", required=True)
    response_level = fields.Selection(RESPONSE_LEVELS, string=u"救援层级")
    unit_type = fields.Selection(SAVE_UNIT_TYPE, string=u"单位类型", required=True)
    role = fields.Selection(SALVAGER_ROLES, string=u"角色", required=True)
    order_number = fields.Integer(string=u"显示顺序", required=True)

    _sql_constraints = [
        ('unique_unit_type_and_role', 'unique(config_type,unit_type,role)', '配置项已经存在，请勿重复添加')
    ]
